** Put together information on the number of kids and age of youngest kid 
** for each mother and father, for use in intergenerational EITC project

** NOTE: According to IPUMS CPS documentation, "MOMLOC will also identify the
** unmarried partner of a child's father identified with POPLOC."  So it seems
** that process for counting up kids of a given mom will capture all of her kids,
** don't need to do the step of adding kids who identify person X as parent and
** kids who identify person X's spouse as parent.
*****************************************************************************

quietly do CPS/cps_00036.do
  

gen under24FTS=(age<24 & (schlcoll==1 | schlcoll==3) &  (marst~=1 & marst~=2)  )
gen under19=(age<19 & (marst~=1 & marst~=2))
gen under18=(age<18 & (marst~=1 & marst~=2))
gen under6=(age<6 & (marst~=1 & marst~=2))
gen under5=(age<5 & (marst~=1 & marst~=2))

save temp, replace


gen mom_pnum = momloc
gen HasMom = (mom_pnum~=0)
gen under24FTS_HasMom = (under24FTS==1 & mom_pnum~=0)
gen under19_HasMom = (under19==1 & mom_pnum~=0)
gen under18_HasMom = (under18==1 & mom_pnum~=0)
gen under6_HasMom = (under6==1 & mom_pnum~=0)
gen under5_HasMom = (under5==1 & mom_pnum~=0)

gen PotentialDep = (under24FTS_HasMom==1 | under19_HasMom==1)

recode mom_pnum 0=.

sort serial year mom_pnum 

by serial year mom_pnum : egen KidCount = total(HasMom)
by serial year mom_pnum : egen klt24m = total(under24FTS_HasMom)
by serial year mom_pnum : egen klt19m = total(under19_HasMom)
by serial year mom_pnum : egen klt18m = total(under18_HasMom)
by serial year mom_pnum : egen klt6m = total(under6_HasMom)
by serial year mom_pnum : egen klt5m = total(under5_HasMom)
by serial year mom_pnum: egen DepCount = total(PotentialDep)


** Save counts of kids for moms
keep serial year mom_pnum  KidCount klt24m klt19m klt18m klt6m klt5m DepCount
duplicates drop 
drop if mom_pnum==.
rename mom_pnum pernum
sort serial year pernum 
save CPS/MomKidCount_temp, replace


clear

** Now read basic file back in and create variables for dads
use temp

gen dad_pnum = poploc
gen HasDad = (dad_pnum~=0)
gen under24FTS_HasDad = (under24FTS==1 & dad_pnum~=0)
gen under19_HasDad = (under19==1 & dad_pnum~=0)
gen under18_HasDad = (under18==1 & dad_pnum~=0)
gen under6_HasDad = (under6==1 & dad_pnum~=0)
gen under5_HasDad = (under5==1 & dad_pnum~=0)

gen PotentialDep = (under24FTS_HasDad==1 | under19_HasDad==1)

recode dad_pnum 0=.

sort serial year dad_pnum 

by serial year dad_pnum : egen KidCount = total(HasDad)
by serial year dad_pnum : egen klt24m = total(under24FTS_HasDad)
by serial year dad_pnum : egen klt19m = total(under19_HasDad)
by serial year dad_pnum : egen klt18m = total(under18_HasDad)
by serial year dad_pnum : egen klt6m = total(under6_HasDad)
by serial year dad_pnum : egen klt5m = total(under5_HasDad)
by serial year dad_pnum : egen DepCount = total(PotentialDep)

** Save counts of kids for dads
keep serial year dad_pnum  KidCount klt24m klt19m klt18m klt6m klt5m DepCount
duplicates drop 
drop if dad_pnum==.
rename dad_pnum pernum
sort serial year pernum 
save CPS/DadKidCount_temp, replace


